<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2019/2/26
 * Time: 9:14
 */

// 如果id有值,就返回一个商品信息
//如果id没有值,返回所有的商品信息
header("content-Type:application/json;charset=utf-8");
header("Access-Control-Allow-Origin:*");
if (isset($_REQUEST["gId"])){
    $GID=$_REQUEST["gId"];

    $goodsStr=file_get_contents("./data/list.json");
    //把字符串转对象
    $goodsList=json_decode($goodsStr);

    for($i=0;$i<count($goodsList);$i++){
        if ($goodsList[$i]->gId==$GID){
            print_r(json_encode($goodsList[$i]));
            break;
        }
    }
}else{
    $goodsStr=file_get_contents("./data/list.json");
    print_r($goodsStr);
}